package com.a2.appa3.ui.activity;

import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.a2.appa3.R;
import com.a2.appa3.global.HttpAdress;
import com.a2.appa3.global.Info;
import com.a2.appa3.model.CustomObserver;
import com.a2.appa3.model.network.HttpJsonUtils;
import com.a2.appa3.model.network.entity.req.changeNikeNameBean;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class changenameDiolog extends Activity {
    private EditText changenike;
    private TextView cancle;
    private TextView conform;
    private String name;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_changename_diolog);
        changenike = findViewById(R.id.changenike);
        cancle = findViewById(R.id.btn_neg);
        conform = findViewById(R.id.btn_pos);
        name = getIntent().getStringExtra("nameid");
        cancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        conform.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (changenike.getText().toString().isEmpty() && !TextUtils.isEmpty(name)) {
                    Toast.makeText(changenameDiolog.this, "输入备注不能为空", Toast.LENGTH_SHORT).show();
                } else {
                    //开始网络请求
                    HttpJsonUtils.getHttpApiInstance()
                            .setRemark(HttpAdress.getuseAdress() + "api/chatapi/User/setRemark", name, changenike.getText().toString().trim(), Info.Token)
                            .subscribeOn(Schedulers.io())
                            .observeOn(AndroidSchedulers.mainThread())
                            .subscribe(new CustomObserver<changeNikeNameBean>() {
                                @Override
                                protected void onCustomNext(changeNikeNameBean resBanner) {
                                    if (resBanner.getCode() == 0) {
                                        Toast.makeText(changenameDiolog.this, "" + resBanner.getMsg(), Toast.LENGTH_SHORT).show();
                                        finish();
                                    }
                                }

                                @Override
                                protected void onSubscribeCustom(Disposable disposable) {
                                }

                                @Override
                                protected void onErrorCustom(Throwable e) {
                                }
                            });
                }
            }
        });
    }
}
